<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts 主体
import resize from '../mixins/resize'
export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '350px'
    },
    btDat: {
      type: Array,
      default: () => {
        return []
      }
    },
    title: {
      type: String,
      default: '信息'
    }
  },
  watch: {
    btDat(data, value) {
      this.$nextTick(() => {
        this.initChart(data)
      })
    }
  },
  data() {
    return {
      chart: null,
      lineDate: {},
      facility: [{ value: 10, name: '8寸设备型号' }, { value: 20, name: '10寸设备型号' }]
    }
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart(data) {
      this.chart = echarts.init(this.$el, 'macarons')
      this.chart.setOption({
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          type: 'scroll',
          orient: 'vertical',
          right: 20,
          data: data,
          textStyle: {
            color: '#999999'
          },
          icon: "circle"
        },

        series: [
          {
            name: this.title,
            type: 'pie',
            radius: ['50%', '70%'],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: '12',
                fontWeight: 'bold',
              }
            },
            labelLine: {
              show: false
            },
            data: data,
            animationEasing: 'cubicInOut',
            animationDuration: 2600
          }
        ]
      })
    }
  }
}

</script>
